<?php

namespace app\api\controller;


use think\Controller;
use think\Log;

class Weixin extends Controller {
    public function index() {
        if ($this->checkSignature()) {
            Log::write($_GET["echostr"], 'debug');
            echo $_GET["echostr"];
            exit;
        }
    }

    public function save() {
        Log::write(input('post.'), 'debug');
        return 'success';
    }

    private function checkSignature() {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce     = $_GET["nonce"];

        $token  = '0479xmwsh';
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        Log::write($tmpStr, 'debug');
        if ($tmpStr == $signature) {
            return true;
        } else {
            return false;
        }
    }
}